package com.tanhua.server.controller;

import com.tanhua.model.vo.MovementVo;
import com.tanhua.model.vo.MovementsVo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.VisitorsVo;
import com.tanhua.server.service.MovementService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;
import java.util.Map;

/**
 * 圈子控制层
 */
@RestController
@RequestMapping("/movements")
public class MovementController {

    @Autowired
    private MovementService movementService;

    /**
     * 圈子-发布动态
     *  接口文档存在问题：public ResponseEntity addMovement(@RequestBody Map<String,String> params){
     */
    @RequestMapping(method = RequestMethod.POST)
    public ResponseEntity addMovement(MovementVo movementVo, MultipartFile[] imageContent){
        movementService.addMovement(movementVo,imageContent);
        return ResponseEntity.ok(null);
    }

    /**
     * 圈子-个人动态（我的动态 首页某个佳人动态数据）
     */
    @RequestMapping(value = "/all",method = RequestMethod.GET)
    public ResponseEntity findPageMovement(@RequestParam(value = "page",defaultValue = "1") Long page, @RequestParam(value = "pagesize",defaultValue = "10")Long pageSize,Long userId){
        PageResult<MovementsVo> pageResult = movementService.findPageMovement(page,pageSize,userId);
        return ResponseEntity.ok(pageResult);
    }


    /**
     * 好友动态
     */
    @RequestMapping(method = RequestMethod.GET)
    public ResponseEntity findFriendPageMovement(@RequestParam(value = "page",defaultValue = "1") Long page, @RequestParam(value = "pagesize",defaultValue = "10")Long pageSize){
        PageResult<MovementsVo>  movementsVoPageResult = movementService.findFriendPageMovement(page,pageSize);
        return ResponseEntity.ok(movementsVoPageResult);
    }

    /**
     * 推荐动态
     */
    @RequestMapping(value = "/recommend",method = RequestMethod.GET)
    public ResponseEntity findRecommendPageMovement(@RequestParam(value = "page",defaultValue = "1") Long page, @RequestParam(value = "pagesize",defaultValue = "10")Long pageSize){
        PageResult<MovementsVo>  movementsVoPageResult = movementService.findRecommendPageMovement(page,pageSize);
        return ResponseEntity.ok(movementsVoPageResult);
    }


    /**
     * 单条动态
     */
    @RequestMapping(value = "/{id}",method = RequestMethod.GET)
    public ResponseEntity findMovement(@PathVariable("id") String publishId){
        MovementsVo movementsVo = movementService.findMovement(publishId);
        return ResponseEntity.ok(movementsVo);
    }


    /**
     * 动态点赞
     * publishId:动态id
     * @return
     */
    @RequestMapping(value = "/{id}/like",method = RequestMethod.GET)
    public ResponseEntity like(@PathVariable("id") String publishId) {
        Integer count = movementService.like(publishId);
        return ResponseEntity.ok(count);
    }


    /**
     * 动态取消点赞
     * @return
     */
    @RequestMapping(value = "/{id}/dislike",method = RequestMethod.GET)
    public ResponseEntity dislike(@PathVariable("id") String publishId) {
        Integer count = movementService.dislike(publishId);
        return ResponseEntity.ok(count);
    }


    /**
     * 首页-我的访客
     * @return
     */
    @RequestMapping(value = "/visitors",method = RequestMethod.GET)
    public ResponseEntity findvisitors() {
        List<VisitorsVo> list  = movementService.findvisitors();
        return ResponseEntity.ok(list);
    }
}
